#include <stdio.h>
#include <stdlib.h>
#define ROWS 3
#define COLLUMNS 4
char function(char, int);
char function1(char, char);
int main()
{
    int c, ok = 1;
    char state = 'A';
    FILE *fp;
    fp = fopen("in.txt", "r+");
    while ((c = fgetc(fp)) != '\n')
    {
        if (c != 'a' && c != 'b' && c != 'c')
            ok = 0;
        state = function1(state, c);
    }
    if (ok == 1)
        if (state == 'B')
            printf("I know the word.");
        else
            printf("I do not know the word.");
    else
        printf("I do not know the word.");
    fclose(fp);
    return 0;
}
char function(char st, int ch)
{
    if (st == 'A' && (ch == 'b' || ch == 'c'))
        return 'A';
    if (st == 'A' && ch == 'a')
        return 'B';
    if (st == 'B' && (ch == 'b' || ch == 'c' || ch == 'a'))
        return 'B';
    return 'X';
}
char function1(char st, char ch)
{
    int i, r = 0, c = 0;
    char matrix[ROWS][COLLUMNS] = {{'0', 'a', 'b', 'c'}, {'A', 'B', 'A', 'A'}, {'B', 'B', 'B', 'B'}};
    for (i = 1; i < COLLUMNS; ++i)
        if (matrix[0][i] == ch)
            c = i;
    for (i = 1; i < ROWS; ++i)
        if (matrix[i][0] == st)
            r = i;
    return matrix[r][c];
}

